#!/bin/sh  
########
# SWISH installation script for Hot Mix 17.
# G. Helms, 7/23/97
# My profoundest apologies for the horrible condition of this script.
# If you think THIS is bad, you should have seen the previous version!
# I apologize in advance if you have to wade through this muck.  
# If you have any questions, I can be reached at ghelms@sgi.com and can 
# help you with any problems.
########

# Grab the location of where Hot Mix is on the CD path, especially the
# html dir where all our files for the search engine are.
set CD_PATH $HOTMIXDIR/html
cd $CD_PATH
export CD_PATH

# Inform the user of what we're about to do.
cat << 'EOM'


The Hot Mix 17 CDROM uses a search engine that needs to copy a 
cgi-bin program from the CD to your cgi-bin directory or document 
root, and a search file to your /usr/tmp directory.  

This installation program has two modes:
1.  Automatic.  If you answer yes to the question, "Proceed with 
automatic installation?", the script will try to copy the neccessary
files to their correct locations.
2.  Custom.  If you answer no to the question, "Proceed with
automatic installation?", the script will ask you if you want
to proceed with a custom installation, and will ask you where
your document root and cgi-bin directories are and will try to
install the neccessary files to their correct locations.

>>>Beginning installation process.

EOM

# Automatic mode.  /var/www is doc root; /var/www/cgi-bin is default.
echo  ">>>Proceed with automatic installation? [yn] $c"
read ans
case $ans in
        y*) echo ""

# Informative note only, this info not used by script.
	    echo "Checking the server type on your system..."
	    if /bin/test -d /var/www/server
	    then
	      echo "You have an NCSA server on your system."
	    else
              if /bin/test -d /usr/ns-home
		then
		  echo "You have a Netscape server on your system."
		else
		  echo ">>>Can't find NCSA or Netscape servers in the default places."
		  echo ">>>Please consult your Webmaster to find out where they may"
		  echo ">>>be located on your system, and run the custom install."
	          echo ">>>SWISH NOT INSTALLED.  PROGRAM EXITING.<<<"
		  exit 1
	      fi
	    fi

# Install things in their expected locations.
	      echo ""
	      echo "Installing swshsrch.cgi to /var/www/cgi-bin..."
	      echo ""
	      if /bin/test -w /var/www/cgi-bin
       	      then
# Must substitute correct path to CD-based files into your version.
                /usr/bin/sed s:swish:$CD_PATH/swish.11/swish: $CD_PATH/cgi-bin/swshsrch.cgi > /usr/tmp/tempswish
# Make sure swish looks at an index that's built right.
		if /bin/test -d /CDROM/iso9660
                 then
                  /usr/bin/sed s:index.swish:$CD_PATH/swish.11/indexiso.swish: /usr/tmp/tempswish > /var/www/cgi-bin/swshsrch.cgi
                 else
                  /usr/bin/sed s:index.swish:$CD_PATH/swish.11/index.swish: /usr/tmp/tempswish > /var/www/cgi-bin/swshsrch.cgi
                fi
                /usr/bin/rm /usr/tmp/tempswish
                /usr/bin/chmod 755 /var/www/cgi-bin/swshsrch.cgi
                /usr/bin/sed s:setup.csh:$HOTMIXDIR/html/setup.csh: $HOTMIXDIR/html/search.html > /usr/tmp/hm17search.html
	       else
                echo ">>>I can't write to that location.  You'll need to log in
as root."
                echo "Logging in as root...you may need to supply the root password."
                if /bin/test -d /CDROM/iso9660
                 then
                  su root -c "/usr/bin/sed s:swish:$CD_PATH/swish.11/swish: $CD_PATH/cgi-bin/swshsrch.cgi > /usr/tmp/tempswish;/usr/bin/sed s:index.swish:$CD_PATH/swish.11/indexiso.swish: /usr/tmp/tempswish > /var/www/cgi-bin/swshsrch.cgi;/usr/bin/rm /usr/tmp/tempswish;/usr/bin/chmod 755 /var/www/cgi-bin/swshsrch.cgi;/usr/bin/sed s:setup.csh:$HOTMIXDIR/html/setup.csh: $HOTMIXDIR/html/search.html > /usr/tmp/hm17search.html"
                 else
                su root -c "/usr/bin/sed s:swish:$CD_PATH/swish.11/swish: $CD_PATH/cgi-bin/swshsrch.cgi > /usr/tmp/tempswish;/usr/bin/sed s:index.swish:$CD_PATH/swish.11/index.swish: /usr/tmp/tempswish > /var/www/cgi-bin/swshsrch.cgi;/usr/bin/rm /usr/tmp/tempswish;/usr/bin/chmod 755 /var/www/cgi-bin/swshsrch.cgi;/usr/bin/sed s:setup.csh:$HOTMIXDIR/html/setup.csh: $HOTMIXDIR/html/search.html > /usr/tmp/hm17search.html"
                fi
		echo "Finished installing as root...logged out of root account."                echo ""
		fi
		servers=`/sbin/ps -ef | /sbin/grep httpd | /sbin/wc -l`
                servnum=`echo $servers`
                case $servnum in
                  0) echo ">>>I don't see an httpd process running for your server."
                     echo ">>>The search engine won't work without a Web server running."
                     echo "Please consult with your Webmaster."
		     echo "";;
          	  1) echo ">>>I don't see an httpd process running for your server."
	             echo ">>>The search engine won't work without a Web server running."
                     echo "Please consult with your Webmaster."
	             echo "";;
                  *) echo "You appear to have a server running."
		     echo ""
        	 esac
	        echo ""
	        echo "You should be able to exit this window, reload the Search page" 
		echo "and begin using SWISH.  If SWISH won't work, please consult"
	        echo "your Webmaster for help."
	        echo ""
    		echo ">>>DONE WITH INSTALL<<<"
	    exit ;;
#
# Done with default installation.
#
	n*) echo ">>>Proceed with custom installation questions and install? [yn] $c"
	    read custom
	    case $custom in
	     n*) echo ""
		 echo ">>>Exiting installation program.  Search engine NOT installed."
		 echo ">>>DONE WITH INSTALL<<<"
 	         exit ;;
	     y*) echo ""
		 echo ">>>Please type in the full directory path to the "
                 echo "document root on your system."
                 read docroot
		 echo ">>>Do you have CGI turned on as a filetype? [yn]"
	         read filetype
	         case $filetype in 
		  y*)  echo ""
		       echo "The swshsrch.cgi program will be placed at the top"
		       echo "of your document root." 
			putcgihere=$docroot;;
		  n*)  echo ""
		       echo ">>>This program assumes your cgi-bin directory is under"
		       echo "your document root."
		       echo "Here is a list of directories with cgi in their name:"
                       cd $docroot
                       find . -type d -name "*cgi*" -print
                       echo ">>>Please type in the primary cgi-bin directory.  Do not include"
                       echo ">>>the leading ./"
                       read wherecgi
		       cgiplace=$wherecgi/
		       putcgihere=$docroot/$cgiplace
		 esac
		 export putcgihere 
		 export cgiplace
		 if /bin/test -w $putcgihere
                   then
		     echo ""
                     echo "Copying the program..."
		     echo ""
		     /usr/bin/sed s:swish:$CD_PATH/swish.11/swish: $CD_PATH/cgi-bin/swshsrch.cgi > /usr/tmp/tempswish
		     if /bin/test -d /CDROM/iso9660
                      then
                      /usr/bin/sed s:index.swish:$CD_PATH/swish.11/indexiso.swish: /usr/tmp/tempswish > $putcgihere/swshsrch.cgi
                      else
                      /usr/bin/sed s:index.swish:$CD_PATH/swish.11/index.swish: /usr/tmp/tempswish > $putcgihere/swshsrch.cgi
                     fi
                     /usr/bin/rm /usr/tmp/tempswish
                     /usr/bin/chmod 755 $putcgihere/swshsrch.cgi
		     /usr/bin/sed s:cgi-bin/swshsrch.cgi:${cgiplace}swshsrch.cgi: $CD_PATH/search.html > /usr/tmp/tempsearch.html
		     /usr/bin/sed s:setup.csh:$HOTMIXDIR/html/setup.csh: /usr/tmp/tempsearch.html > /usr/tmp/hm17search.html
		     /usr/bin/rm /usr/tmp/tempsearch.html
                 else
		     echo ">>>I can't write to that location.  Hang on a sec...."
                     if /bin/test -d $putcgihere
                         then
                           echo "Directory exists..."
			   echo ">>>You'll need to log in as root.  Please supply the"
			   echo ">>>root password if asked."
			   if /bin/test -d /CDROM/iso9660
                            then
		             su root -c "/usr/bin/sed s:swish:$CD_PATH/swish.11/swish: $CD_PATH/cgi-bin/swshsrch.cgi > /usr/tmp/tempswish; /usr/bin/sed s:index.swish:$CD_PATH/swish.11/indexiso.swish: /usr/tmp/tempswish > $putcgihere/swshsrch.cgi; /usr/bin/rm /usr/tmp/tempswish; /usr/bin/chmod 755 $putcgihere/swshsrch.cgi; /usr/bin/sed s:cgi-bin/swshsrch.cgi:${cgiplace}swshsrch.cgi: $CD_PATH/search.html > /usr/tmp/tempsearch.html; /usr/bin/sed s:setup.csh:$HOTMIXDIR/html/setup.csh: /usr/tmp/tempsearch.html > /usr/tmp/hm17search.html; /usr/bin/rm /usr/tmp/tempsearch.html"
		            else
		             su root -c "/usr/bin/sed s:swish:$CD_PATH/swish.11/swish: $CD_PATH/cgi-bin/swshsrch.cgi > /usr/tmp/tempswish; /usr/bin/sed s:index.swish:$CD_PATH/swish.11/index.swish: /usr/tmp/tempswish > $putcgihere/swshsrch.cgi; /usr/bin/rm /usr/tmp/tempswish; /usr/bin/chmod 755 $putcgihere/swshsrch.cgi; /usr/bin/sed s:cgi-bin/swshsrch.cgi:${cgiplace}swshsrch.cgi: $CD_PATH/search.html > /usr/tmp/tempsearch.html; /usr/bin/sed s:setup.csh:$HOTMIXDIR/html/setup.csh: /usr/tmp/tempsearch.html > /usr/tmp/hm17search.html; /usr/bin/rm /usr/tmp/tempsearch.html"
		            fi
		           echo "Finish installing as root...logged out of root account."
                         else
			   echo ""
                           echo ">>>Directory doesn't exist...you'll need to create it and"
                           echo ">>>run the setup script again.  Search engine NOT installed."
			   echo ""
			   echo ">>>EXITING INSTALL PROGRAM<<<"
		           exit 1;
		         fi
		     fi
		     servers=`/sbin/ps -ef | /sbin/grep httpd | /sbin/wc -l`
                     servnum=`echo $servers`
                     case $servnum in
                      0) echo ""
		 	 echo ">>>I don't see an httpd process running for your server."
                         echo ">>>The search engine won't work without a Web server running."
                         echo "Please consult with your Webmaster.";;
                      1) echo ">>>I don't see an httpd process running for your server."
                         echo ">>>The search engine won't work without a Web server running."
                         echo "Please consult with your Webmaster.";;
                      *) echo "You appear to have a server running."
                         echo ""
                    esac 
		    echo ""
                    echo "You should be able to exit this window, reload the Search page"
                    echo "and begin using SWISH.  If SWISH won't work, please consult"
                    echo "your Webmaster for help."
                    echo ""
                    echo ">>>DONE WITH INSTALL<<<";;
	    esac
esac

